package com.LeeCode;

import java.util.HashMap;

/**
 * 森林中的兔子
 */

public class Code781 {
    public static void main(String[] args) {
        int[] answers = {10, 10, 10};
        System.out.println(new Code781().numRabbits(answers));

    }

    public int numRabbits(int[] answers) {
        int ans = 0;
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int num : answers) { // 进行计数
            map.put(num, map.getOrDefault(num, 0) + 1);
        }

        for (int key : map.keySet()) {
            // 统计有几个颜色组
            int numCluster = (int) Math.ceil(map.get(key) / (double) (key + 1));
            ans += numCluster * (key + 1);
        }
        return ans;
    }
}
